package com.example.practice2023.controller;

import com.example.practice2023.pojo.Good;
import com.example.practice2023.service.GoodService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/good")
public class GoodController {
    @Resource
    private GoodService goodService;
    @RequestMapping(value = "/selectById",method = RequestMethod.GET)
    public Map<String,Object> selectById(@RequestParam Integer goodId) {

        return goodService.selectById(goodId);
    }
//
    @RequestMapping(value = "/selectByPage",method = RequestMethod.GET)
    public Map<String,Object> selectByPage(int page,int limit,Good good) {
        System.out.printf("page=",page);
        return goodService.selectByPage(page, limit,good);
    }

    @RequestMapping(value = "/insert",method = RequestMethod.POST)
    public Map<String,Object> insert(@RequestBody Good good){
        return goodService.insert(good);
    }

    @RequestMapping(value = "/updateById",method = RequestMethod.POST)
    public Map<String,Object> updateById(@RequestBody Good good){
        return goodService.updateById(good);
    }

    @RequestMapping(value = "/deleteById",method = RequestMethod.POST)
    public Map<String,Object> deleteById(@RequestParam Integer goodId){
        return goodService.deleteById(goodId);
    }
}
